<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page contentType="text/html;charset=utf-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<link href="joju.css" rel="stylesheet" type="text/css" />

<link href="../css/idelta.css"/>
<link href="../css/tabbed_panel.css"/>
<link href="../css/application.css"/>
<script type="text/javascript" src="../js/ajax-basics.js"/>
<script type="text/javascript" src="/js/ajax-basics.js"/>
<script type="text/javascript" src="../js/dojo/dojo.js"/>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>


<script type="text/javascript">
	var djConfig = { isDebug: false };
</script>
<script type="text/javascript" src="../js/dojo/dojo.js">/*_*/</script>


<script type="text/javascript">
/* Initial Nodes */
var treeDat = {
	treeNodes: [
		{ title:"Customer" }
	]
};
</script>

<script type="text/javascript">
/* Initial Nodes */

 function titleClicked(event){
	  var e=window.event;
	  var text = event.srcElement.innerText;
	  text = text.substring(text.indexOf(':')+1);	 
		   var temp = new Array();
		   temp = text.split('|');
		   var url = "../DojoDemoServlet?CustomerID="+escape(temp[1]);
		   sendRequest(url);
  }


 function onNodeClick(event){
			var e=window.event;
			var txt = event.srcElement.innerText;
		   alert("onNodeClick");
		     
			if(txt.indexOf("|") !=-1)
				{
						var mySplitResult = txt.split("|");
						if ((mySplitResult.length>1) ||
						   (mySplitResult[1].value==null)) {
							alert(txt);
							//alert(mySplitResult[1]);
							getdata(mySplitResult[1]);
						   }
						   

							
				}

		   //var url = "../CustomerServlet?CustomerAccountID="+escape(temp[1]);
			//var url = "../CustomerServlet?CustomerAccountID=100066181";
			//getdata("100066181");
			//getdata(text);
		  // sendRequest(url);
  }



</script>
<script>


var request;
var xmlHttp ;
var functionname;

function popUpAddChild()


{


      var window2 = window.open('../pages/AddChild.tiles','myWindow','width=790,height=520,scrollbars=yes,menubar=no,status=yes,resizable=yes,directories=false,location=1,left=0,top=0');
      // var testwin=window.open('../pages/AddChild.tiles', 'popupWindowName', 'dependent=yes, menubar=no, toolbar=no'); 
      
}

	function AddCustomer()
		{	 
		 var Parentname=document.getElementById("addChildparent").options[document.getElementById("addChildparent").selectedIndex].value;
		 
         var Scope=document.getElementById("addChildScope").options[document.getElementById("addChildScope").selectedIndex].value;
         var Country=document.getElementById("addChildCountry").options[document.getElementById("addChildCountry").selectedIndex].value;
         var ShortName=document.getElementById("addChildshortName").value;
         var LongName=document.getElementById("addChildlongName").value;
        //var  Status=document.getElementById("addChildStatus").options[document.getElementById("addChildStatus").selectedIndex].value;
         var  Status="O";
         var  EnId=document.getElementById("addChildentity").options[document.getElementById("addChildentity").selectedIndex].value;
         var System=document.getElementById("addChildSystem").options[document.getElementById("addChildSystem").selectedIndex].value;
         var  Type=document.getElementById("addChildType").options[document.getElementById("addChildType").selectedIndex].value;
         var classfication=document.getElementById("addChildClassification").options[document.getElementById("addChildClassification").selectedIndex].value;
         var  CallbackMethod=document.getElementById("addChildcallback").options[document.getElementById("addChildcallback").selectedIndex].value;
         var  ReturnPriority=document.getElementById("addChildcollreturn").options[document.getElementById("addChildcollreturn").selectedIndex].value;
		  var AutoBorrowRet=document.getElementById("addChildAutoBorrowReturn").checked;
		  var Autowrap=document.getElementById("addChildautowarp").checked;
		
		   if(AutoBorrowRet="true")
         {
            AutoBorrowRet="Y";
         }
        else
         {
           AutoBorrowRet="N";
         }

          
         if(Autowrap="true")
         {
            Autowrap="Y";
         }
        else
         {
           Autowrap="N";
         }



         var url = "../AddCustomer?Parentname="+Parentname+"&Scope="+Scope+"&Country="+Country+"&ShortName="+ShortName+"&LongName="+LongName+"&Status="+Status+"&EnId="+EnId+"&System="+System+"&Type="+Type+"&AutoBorrowRet="+AutoBorrowRet+"&Autowrap="+Autowrap+"&CallbackMethod="+CallbackMethod+"&ReturnPriority="+ReturnPriority+"&classfication="+classfication;
		  
         alert(url);
         saveRequest(url);
}


function SerachCustomer()
{
    var  EnId=document.getElementById("SearchEntityId").options[document.getElementById("SearchEntityId").selectedIndex].value;
    var Name=document.getElementById("name").value;
    var url = "../CustomerSerachServelt?EnId="+EnId+"&Name="+Name;
      // document.Customerlist.action=url;
	  // document.Customerlist.submit();

     saveRequest(url);

}
function AddContact()
		{
		alert("AddContact");
		 var contact=document.getElementById("contactnew").value;
		  var CuId=document.getElementById("ideltaCuid").value;
		    var coid=CuId;
         var dept=document.getElementById("dept").value;
         var phone=document.getElementById("phone").value;
         var fax=document.getElementById("fax").value;
         var email=document.getElementById("email").value;
		   var web=document.getElementById("web").value;
		    var address=document.getElementById("address").value;
         var url = "../AddContact?dept="+dept+"&contact="+contact+"&phone="+phone+"&fax="+fax+"&email="+email+"&web="+web+"&address="+address+"&CuId"+CuId+"&coid"+coid;		  
         alert(url);
         saveRequest(url);
}
function AddMap(){
var system=document.getElementById("sys").value;
var alias=document.getElementById("alias").value;
 var url = "../AddMap?system="+system+"&alias="+alias;		  
         alert(url);
         saveRequest(url);

}

function AddParam(){
var pName=document.getElementById("pName").value;
var pValue=document.getElementById("pValue").value;
 var url = "../AddParam?pName="+pName+"&pValue="+pValue;		  
         alert(url);
         saveRequest(url);

}
function SaveCustomer()
{
 
         // this servelt calling used for Save the details of a customer  
         var CuId=document.getElementById("CudId").value;
         var releaseName=document.getElementById("releaseName").options[document.getElementById("releaseName").selectedIndex].value;
         var dBName=document.getElementById("dBType").options[document.getElementById("dBType").selectedIndex].value;
		 var objectType=document.getElementById("objectType").options[document.getElementById("objectType").selectedIndex].value;
         var objectName=document.getElementById("objectName").value;
         var userUpdated=document.getElementById("userUpdated").value;
		 var contactPerson=document.getElementById("contactPerson").value;
         var url = "../CustomerUpdate?CuId="+CuId+"&releaseName="+releaseName+"&dBName="+dBName+"&objectType="+objectType+"&objectName="+objectName+"&userUpdated="+userUpdated+"&contactPerson="+contactPerson;
         alert(url);
         saveRequest(url);
}


function getdata(str)
{
   // this servelt calling used for get details of customer on click of the node 
   var url = "../CustomerServlet?CustomerAccountID="+str;
   alert(url);
   sendRequest(url);

}


function getRequestObject() {
  if (window.ActiveXObject) {
    return(new ActiveXObject("Microsoft.XMLHTTP"));
  } else if (window.XMLHttpRequest) {
    return(new XMLHttpRequest());
  } else {
    return(null);
  }
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}


function saveRequest(address) {
  xmlHttp = GetXmlHttpObject();
  xmlHttp.onreadystatechange = showSaveResponseText;
  xmlHttp.open("GET", address, false);
  xmlHttp.send(null);
}


function showSaveResponseText() {
  if ((xmlHttp.readyState == 4) &&
      (xmlHttp.status == 200)) {


              // alert(xmlHttp.responseText);

              // var xmlDoc=xmlHttp.responseXML.documentElement;
  }
}



function sendRequest(address) {
  xmlHttp = GetXmlHttpObject();
  xmlHttp.onreadystatechange = showResponseText;
  xmlHttp.open("GET", address, true);
  xmlHttp.send(null);
}


function showResponseText() {
  if ((xmlHttp.readyState == 4) &&
      (xmlHttp.status == 200)) {


              // alert(xmlHttp.responseText);

				  var xmlDoc=xmlHttp.responseXML.documentElement;
                 // for main 
				  document.getElementById("CudId").value=xmlDoc.getElementsByTagName("CUID")[0].childNodes[0].nodeValue;
				  UpdateList("releaseName",xmlDoc.getElementsByTagName("RELEASENAME")[0].childNodes[0].nodeValue);
                  UpdateList("dBType",xmlDoc.getElementsByTagName("DBNAME")[0].childNodes[0].nodeValue);
				  UpdateList("objectType",xmlDoc.getElementsByTagName("OBJTYPE")[0].childNodes[0].nodeValue);
                  document.getElementById("objectName").value=xmlDoc.getElementsByTagName("OBJNAME")[0].childNodes[0].nodeValue;
                  document.getElementById("userUpdated").value=xmlDoc.getElementsByTagName("USERUPDATED")[0].childNodes[0].nodeValue;
				  document.getElementById("contactPerson").value=xmlDoc.getElementsByTagName("CONTACTPERSON")[0].childNodes[0].nodeValue;
				         
  
       }


}



function UpdateList(objname,value)
{
      var lis=document.getElementById(objname);
      // iterating through list 

      //alert(objname);
     
      var strvalue;
       for (var i=0; i<lis.length; i++) 
     {

      strvalue=lis.options[i].value;
      if(strvalue==value)
        {
        // alert("optionvale from list :"+strvalue+"CUSoptionvale :"+value);
         document.getElementById(objname).selectedIndex=i;
         break;
        }
     }
}

</script>



<script type="text/javascript">
dojo.addOnLoad(function(){
	dojo.require("dojo.lang.*");
	dojo.require("dojo.widget.Tree");
	dojo.require("dojo.widget.TreeNode");
	dojo.require("dojo.widget.TreeRPCController");
	

var TreeBuilder = {
	buildTreeNodes:function (dataObjs, treeParentNode){
		for(var i=0; i<dataObjs.length;i++){
			var node =  dojo.widget.createWidget("TreeNode",{
				title:dataObjs[i].title,
				isFolder: true,
				widgetId:(((treeParentNode)?treeParentNode.widgetId:"root_")+"_"+i)
			});
			treeParentNode.addChild(node);
			treeParentNode.registerChild(node,i);
		}
	},
	buildTree:function (){
		var myTreeWidget = dojo.widget.createWidget("Tree",{
			widgetId:"myTreeWidget",
			expandIconSrcPlus:"../images/package_obj.gif", 
			 expandIconSrcMinus:"../images/package_obj.gif", 
			 iconWidth:13, 
			 iconHeight:13 


		});
		this.buildTreeNodes(treeDat.treeNodes,myTreeWidget);
		var treeContainer = document.getElementById("myWidgetContainer");
		var placeHolder = document.getElementById("treePlaceHolder");
		treeContainer.replaceChild(myTreeWidget.domNode,placeHolder);
	}
}

TreeBuilder.buildTree();
	var myRpcController = dojo.widget.createWidget("TreeRPCController",{
			widgetId:"treeController",
			RPCUrl:"../DojoDemoServlet"
		});
dojo.event.topic.subscribe("nodeSelected",
			 function(message) { alert(message.node.title+" selected"); });

	myRpcController.onTreeClick = function(message){
		var node = message.source;
		var widget = dojo.widget.getWidgetById('treeController');
		var txt = new String(node);
		if(txt.indexOf("|") !=-1)
				{
						var mySplitResult = txt.split("|");
						if ((mySplitResult.length>1) ||
						   (mySplitResult[1].value==null)) {
							widget.RPCUrl = "../DojoDemoServlet?CustomerID="+txt; 
						   }
						   else { 
								widget.RPCUrl = "../DojoDemoServlet?CustomerID="+txt;
							}

							
				}

		else
		{
		widget.RPCUrl = "../DojoDemoServlet?CustomerID=1";
		}
		if (node.isExpanded){
			this.expand(node);
		} else {
			this.collapse(node);
		}

	}



	myRpcController.onTitleClick = function(message){
		var node = message.source;
		var text = node.objectId;
		widget.RPCUrl = "../DojoDemoServlet?CustomerID="+text;
		if (node.isExpanded){
			this.expand(node);
		} else {
			this.collapse(node);
		}

	}

	var treeContainer = document.getElementById("myWidgetContainer");
	treeContainer.appendChild(myRpcController.domNode);
	myRpcController.listenTree(dojo.widget.manager.getWidgetById("myTreeWidget"));
	});
</script>

</head>

</head>


<body>
<table border="0" cellspacing="0" cellpadding="0" usemap="#Map">
  <tr>
  <td>


  <div id="myWidgetContainer"
                   style="width:239; height:557px; overflow-x:auto;overflow-y:auto;">
	
	
<logic:notEqual name="RecordCount" value="0">

	<span id="treePlaceHolder"
		
		Loading Customertree ...
	</span>
</logic:notEqual>

<logic:equal name="RecordCount" value="0">

<span id="UserInforslt">Search criteria Customer does not exist</span>

</logic:equal>

	</div>


	</td>

  </tr>
</table>


<map name="Map" id="Map"><area shape="rect" coords="117,195,213,217" href="tree_main.jsp" target="treemainFrame" />
</map></body>
</html>
